<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->


<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-cn" xml:lang="zh-cn">
<head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="DC.Type" content="topic">
<meta name="DC.Title" content="步骤1：开启归档模式">
<meta name="product" content="">
<meta name="DC.Relation" scheme="URI" content="antdb-0012.html">
<meta name="prodname" content="">
<meta name="version" content="">
<meta name="brand" content="">
<meta name="DC.Publisher" content="20250306">
<meta name="prodname" content="csbs">
<meta name="documenttype" content="usermanual">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="antdb-0013">
<meta name="DC.Language" content="zh-cn">
<link rel="stylesheet" type="text/css" href="public_sys-resources/commonltr.css">
<title>步骤1：开启归档模式</title>
</head>
<body style="clear:both; padding-left:10px; padding-top:5px; padding-right:5px; padding-bottom:5px"><a name="antdb-0013"></a><a name="antdb-0013"></a>

<h1 class="topictitle1">步骤1：开启归档模式</h1>
<div><p>在执行数据库备份前必须开启归档模式，否则将会导致备份失败。</p>
<div class="section"><h4 class="sectiontitle">注意事项</h4><p>本节操作如无特殊说明均以AntDB 7.0版本为例进行，数据库版本不同操作可能存在差异，请以实际为准。</p>
</div>
<div class="section"><h4 class="sectiontitle">操作步骤</h4><div class="p"><strong>如果是集中式的单机，通过修改配置文件参数开启归档模式。</strong><ol><li>使用PuTTY，登录AntDB数据库主机并切换至root用户。</li><li>创建存放归档日志（WAL日志）的路径，后续操作以/mnt/server/archivedir/路径为例。<pre class="screen">mkdir -p<em> /mnt/server/archivedir/</em></pre>
</li><li>赋予运行数据库的操作系统用户antdb读写权限。<pre class="screen">chmod 750 <em>/mnt/server/archivedir/</em>
chown antdb:antdb <em>/mnt/server/archivedir/</em></pre>
</li><li>执行<strong>su - antdb</strong>切换至用户antdb。系统回显示例如下：<pre class="screen">[root@localhost <font style="font-size:8pt" Face="Courier New" >~</font>]# su - antdb
[antdb@localhost <font style="font-size:8pt" Face="Courier New" >~</font>]$<em>  </em></pre>
</li><li>使用用户antdb登录数据库。<pre class="screen">adb -d antdb -U antdb -p 6655</pre>
</li><li>执行<strong>show config_file</strong><strong>;</strong>查询postgresql.conf文件所在路径。系统回显示例如下：<pre class="screen">postgres=# show config_file;
              config_file
---------------------------------------
 /home/antdb/app/data/postgresql.conf
(1 row)</pre>
</li><li id="antdb-0013__zh-cn_topic_0000001607842332_li17263199293">在键盘上按<span class="uicontrol" id="antdb-0013__zh-cn_topic_0000001607842332_uicontrol173011037123011">“Ctrl+d”</span>退出登录用户antdb，进入AntDB数据库主机。</li><li>进入postgresql.conf文件，这里以/home/antdb/app/data/postgresql.conf路径为例。<pre class="screen">vi /home/antdb/app/data/postgresql.conf</pre>
</li><li>找到并修改postgresql.conf文件中的wal_level 、archive_mode和archive_command参数，如下所示：<pre class="screen">wal_level = replica                     # minimal, replica, or logical
archive_mode = on               # enables archiving; off, on, or always
archive_command = 'cp %p <em>/mnt/server/archivedir</em>/%f'          # command to use to archive a logfile segment</pre>
<div class="note"><img src="public_sys-resources/note_3.0-zh-cn.png"><span class="notetitle"> </span><div class="notebody"><ul><li>将wal_level设置为replica。</li><li>将archive_mode设置为on。</li><li>将archive_command设置为 'cp %p /mnt/server/archivedir/%f'，并确保归档日志的路径是单个路径。</li><li>archive_command只支持cp命令，其他命令不支持。</li><li>修改postgresql.conf文件时，请修改文件中已存在的字段值，禁止在文件中自行新增同样的字段，否则将会影响恢复任务。</li></ul>
</div></div>
</li><li>修改完毕后，按<strong>Esc</strong>，并输入<strong>:wq</strong><strong>!</strong>保存并退出。</li><li>重启数据库。-D参数代表客户自行指定的数据目录。<pre class="screen">adb_ctl restart -D /home/antdb/app/data</pre>
<div class="notice"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-zh-cn.png"> </span><div class="noticebody"><p>重启数据库期间，数据库业务会中断，请谨慎操作。</p>
</div></div>
</li></ol>
</div>
<p><strong>如果是集中式的集群，通过执行数据库命令开启归档模式</strong>。</p>
<ol><li>查询集群主节点和非主节点。<ol type="a"><li>使用PuTTY登录集群任一节点，然后输入<strong>su - antdb</strong>命令切换至运行数据库的操作系统用户。</li><li>执行<strong>adbhamgrctl -c <em>/etc/adbhamgr/</em><em>adbhamgr_antdbcluster.yaml</em> list</strong>（<span id="antdb-0013__ph8640182163413"><em id="antdb-0013__i0348165516338">/etc/adbhamgr/adbhamgr_antdbcluster.yaml</em>请根据实际路径和实际文件名称替换</span>）命令，查询集群的主节点，即<span class="parmname">“Role”</span>为<span class="parmvalue">“Leader”</span>的节点，<span class="parmname">“Role”</span>为其他值的节点为非主节点。如下图所示：<p><span><img src="zh-cn_image_0000002170179306.png"></span></p>
</li></ol>
</li><li>停止所有非主节点AntDB服务，以下操作要依次在每个非主节点执行。<ol type="a"><li id="antdb-0013__li20888192351819">使用PuTTY登录集群非主节点，然后输入<strong id="antdb-0013__b187421117191919">su - antdb</strong>命令切换至运行数据库的操作系统用户。</li><li>执行<strong>systemctl stop adbhamgr</strong>命令停止AntDB服务。</li></ol>
</li><li>配置集群主节点并重启AntDB服务。<ol type="a"><li>使用PuTTY，登录集群主节点的AntDB数据库主机。</li><li id="antdb-0013__li4180164110276"><a name="antdb-0013__li4180164110276"></a><a name="li4180164110276"></a>执行<strong>su - root</strong>切换至root用户，创建存放归档日志（WAL日志）的路径，后续操作以/mnt/server/archivedir/路径为例。<pre class="screen">mkdir -p /mnt/server/archivedir/</pre>
</li><li>赋予运行数据库的操作系统用户antdb有读写权限。<pre class="screen">chmod 750 /mnt/server/archivedir/
chown antdb:antdb/mnt/server/archivedir/</pre>
</li><li>执行<strong>su - antdb</strong>切换至用户antdb。系统回显示例如下：<pre class="screen">[root@localhost <font style="font-size:8pt" Face="Courier New" >~</font>]# su - antdb
[antdb@localhost <font style="font-size:8pt" Face="Courier New" >~</font>]$</pre>
</li><li>使用用户antdb登录数据库。<pre class="screen">adb -d antdb -U antdb -p 6655</pre>
</li><li>依次执行以下3条命令，开启数据库归档模式。<pre class="screen">alter system set wal_level= 'replica';</pre>
<pre class="screen">alter system set archive_mode= 'on';</pre>
<pre class="screen">alter system set archive_command ='cp %p /mnt/server/archivedir/%f';</pre>
<div class="note"><img src="public_sys-resources/note_3.0-zh-cn.png"><span class="notetitle"> </span><div class="notebody"><p>archive_command只支持cp命令，其他命令不支持。</p>
</div></div>
</li><li>在键盘上按<span class="uicontrol" id="antdb-0013__antdb-0013_zh-cn_topic_0000001607842332_uicontrol173011037123011">“Ctrl+d”</span>退出登录用户antdb，进入AntDB数据库主机。</li><li id="antdb-0013__li153292512311"><a name="antdb-0013__li153292512311"></a><a name="li153292512311"></a>重启AntDB服务。<pre class="screen">systemctl restart adbhamgr</pre>
<div class="notice"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-zh-cn.png"> </span><div class="noticebody"><p>重启集群主节点AntDB服务时，数据库业务会中断，请谨慎操作。</p>
</div></div>
</li></ol>
</li><li>启动所有非主节点AntDB服务，以下操作要依次在每个非主节点执行。<ol type="a"><li>使用PuTTY登录集群非主节点，然后输入<strong id="antdb-0013__antdb-0013_b187421117191919">su - antdb</strong>命令切换至运行数据库的操作系统用户。</li><li>执行<strong>systemctl start adbhamgr</strong>命令启动AntDB服务。</li></ol>
</li><li>依次配置所有非主节点并重启AntDB服务。使用PuTTY依次登录每个非主节点，并执行<a href="#antdb-0013__li4180164110276">3.b</a>到<a href="#antdb-0013__li153292512311">3.h</a>。</li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>父主题：</strong> <a href="antdb-0012.html">备份AntDB</a></div>
</div>
</div>

<div class="hrcopyright"><hr size="2"></div><div class="hwcopyright">版权所有 &copy; 华为技术有限公司</div></body>
</html>